package Reeks5.VanRansbeeck.Kevin.Controller;

import Reeks5.VanRansbeeck.Kevin.Model.PokerSpeler;
import Reeks5.VanRansbeeck.Kevin.Model.States.Player.PlayerStateContext;
import Reeks5.VanRansbeeck.Kevin.View.GameGUI;
import Reeks5.VanRansbeeck.Kevin.View.PokerToolbar;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class PokerButtonListener implements ActionListener {
    private GameGUI context;
    private PokerToolbar bar;
    private PokerSpeler s;

   
    public PokerButtonListener(GameGUI gui, PokerToolbar bar) {
        this.context = gui;
        this.bar = bar;
        try {
            this.s = (PokerSpeler)gui.getSpeler();
        } catch (Exception e) {}
        //System.out.println("PokerButtonListener aangemaakt");
        //System.out.println(context);
    }

    public void actionPerformed(ActionEvent ae) {
        
        if(ae.getActionCommand().equalsIgnoreCase("check")) {
            try {
                this.s.check();
            } catch (Exception e) {
                
            }
        } else if(ae.getActionCommand().equalsIgnoreCase("call")) {
            try {
                this.s.call(context.getSpel().getHighestbet());
            } catch (Exception e) {
                
            }
        } else if(ae.getActionCommand().equalsIgnoreCase("bet")) {
            try {
                this.s.bet(bar.getBetValue());
            } catch (Exception e) {
                
            }
        } else if(ae.getActionCommand().equalsIgnoreCase("raise")) {
            try {
                this.s.raise(bar.getRaiseValue());
            } catch (Exception e) {
                
            }
        } else if(ae.getActionCommand().equalsIgnoreCase("fold")) {
            try {
                this.s.fold();
            } catch (Exception e) {
                
            }
        } else if(ae.getActionCommand().equalsIgnoreCase("all-in")) {
            try {
                this.s.allin(bar.getGameGUI().getSpeler().getSaldo());
            } catch (Exception e) {
                
            }
        }
        bar.toggleActionButtons();
        bar.repaint();
    }
}
